using System.Linq;
using YMJake.Flowable.ExternalWorker.Client.Core.Client;

namespace YMJake.Flowable.ExternalWorker.Client.Core.Rest;

public class ExternalWorkerAcquireJobResponse : ExternalWorkerJobResponse, IAcquiredExternalWorkerJob
{
    public Dictionary<string, object?> Variables { get; }

    public ExternalWorkerAcquireJobResponse(
        string id,
        string url,
        string? correlationId,
        string? processInstanceId,
        string? executionId,
        string? scopeId,
        string? subScopeId,
        string? scopeDefinitionId,
        string? scopeType,
        string? elementId,
        string? elementName,
        int retries,
        string? exceptionMessage,
        DateTime? dueDate,
        DateTime? createTime,
        string? tenantId,
        string? lockOwner,
        DateTime? lockExpirationTime,
        List<EngineRestVariable>? variables)
        : base(id, url, correlationId, processInstanceId, executionId, scopeId, subScopeId, scopeDefinitionId,
            scopeType, elementId, elementName, retries, exceptionMessage, dueDate, createTime, tenantId, lockOwner,
            lockExpirationTime)
    {
        Variables = (variables ?? new List<EngineRestVariable>())
            .Where(v => !string.IsNullOrWhiteSpace(v.Name))
            .ToDictionary(v => v.Name!, v => v.Value, StringComparer.Ordinal);
    }
}
